package me.ingxin.android.activitylauncher.app

import android.content.Intent
import android.os.Bundle
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import me.ingxin.android.activitylauncher.app.databinding.ActivityMainBinding
import me.ingxin.android.activitylauncher.launchActivityForResult

class MainActivity : AppCompatActivity() {

    private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        binding.btnStart.setOnClickListener {
//            launchActivityForResult(TargetActivity::class.java) {
//                val str = it.data?.getStringExtra("result_str") ?: "没有返回"
//                binding.tvShow.text = "activity结果:$str"
//            }

            launchActivityForResult<Intent, ActivityResult>(
                Intent(this, TargetActivity::class.java),
                ActivityResultContracts.StartActivityForResult(),
                null
            ){
                val str = it.data?.getStringExtra("result_str") ?: "没有返回"
                binding.tvShow.text = "activity结果:$str"
            }

        }
    }


}